package com.icedevcloud.upms.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.icedevcloud.common.core.exception.ApiException;
import com.icedevcloud.upms.controller.admin.tenant.dto.AddTenantReqDto;
import com.icedevcloud.upms.controller.admin.tenant.dto.UpdateTenantReqDto;
import com.icedevcloud.upms.entity.SysTenant;
import com.icedevcloud.upms.mapper.SysTenantMapper;
import com.icedevcloud.upms.service.ISysTenantService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 租户表 服务实现类
 * </p>
 *
 * @author XiaoBingBy
 * @since 2023-08-13
 */
@Service
public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant> implements ISysTenantService {

    @Override
    public Boolean add(AddTenantReqDto reqDto) {
        SysTenant sysTenant = BeanUtil.copyProperties(reqDto, SysTenant.class);
        return this.save(sysTenant);
    }

    @Override
    public Boolean update(UpdateTenantReqDto reqDto) {
        SysTenant sysTenant = this.getById(reqDto.getId());
        if (sysTenant == null) {
            throw new ApiException("租户不存在");
        }
        BeanUtil.copyProperties(reqDto, sysTenant);
        return this.updateById(sysTenant);
    }

    @Override
    public Boolean delete(Long id) {
        SysTenant sysTenant = this.getById(id);
        if (sysTenant == null) {
            throw new ApiException("租户不存在");
        }
        return this.removeById(id);
    }

}
